package com.nti56.springboot.exception;

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class NoPermissionException {
    
	
    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView handleShiroException(Exception ex) {
    	ModelAndView modelAndView = new ModelAndView();
	    modelAndView.setViewName("403");	    
	    modelAndView.addObject("msg", ex.getMessage());
	    return modelAndView;
    }
    
    
    @ExceptionHandler(AuthorizationException.class)
    public ModelAndView AuthorizationException(Exception ex) {
    	ModelAndView modelAndView = new ModelAndView();
	    modelAndView.setViewName("403");	    
	    modelAndView.addObject("msg", ex.getMessage());
	    return modelAndView;
    }
}
